// 工具js

//js执行等待
function sleep(delay) {
    var start = (new Date()).getTime();
    while ((new Date()).getTime() - start < delay) {
        continue;
    }
}


/**
 * 字符串占位符
 * var str1 = "hello {0}".signMix("world"); //hello world
 var str2 = "{0}总冠军, {1}总冠军".signMix("湖人", "骑士"); // 湖人总冠军，骑士总冠军
 var user = {name: "James",sex: "male",age: 34};
 var str3 = "史上第一个30000+8000+8000球员：{name}, 性别{sex}, 今年{age}岁".signMix(user);
 //史上第一个30000+8000+8000球员：James, 性别male, 今年34岁
 var optionData= {name: "flower",selected:true, spell: "abc", value:"1"};
 var optionStr='<option value="{value}" match="{spell}" selected="{selected}">{name}</option>'.signMix(optionData)
 //<option value="1" match="abc" selected="true">flower</option>
 * @type {*|*|*}
 */
String.prototype.signMix = function () {
    if (arguments.length === 0) return this;
    var param = arguments[0], str = this;
    if (typeof (param) === 'object') {
        for (var key in param)
            str = str.replace(new RegExp("\\{" + key + "\\}", "g"), param[key]);
        return str;
    } else {
        for (var i = 0; i < arguments.length; i++)
            str = str.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
        return str;
    }
};


/**
 * 生成数据表
 * @param jq_element
 */
function drawDataTable(jq_element) {
    return $(jq_element).dataTable({
        // 解决多次初始化问题
        retrieve: true,
        // 国际化
        "language": {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            // 排序方式
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        }
    });
}